<%= form_for @puppetclass, :url => (@puppetclass.new_record? ? puppetclasses_path : puppetclass_path(:id => @puppetclass)) do |f| %>
  <%= base_errors_for @puppetclass %>
  <% unless @puppetclass.errors.empty? %>
    <%= alert :class => 'alert-danger', :header => '', :text => _("The class could not be saved because of an error in one of the class parameters.") %>
  <% end %>
  <ul class="nav nav-tabs" data-tabs="tabs">
    <li class="active"><a href="#primary" data-toggle="tab"><%= _('Puppet Class') %></a></li>
    <li><a href="#smart_class_param" data-toggle="tab"><%= _('Smart Class Parameter') %></a></li>
  </ul>

  <div class="tab-content">
    <div class="tab-pane active" id="primary">
      <%= text_f f, :name, :disabled => true %>
      <%= text_f f, :environments, :value => @puppetclass.environments.map(&:name).to_sentence, :label=> _('Puppet environments'), :disabled => true %>
      <%= multiple_checkboxes f, :hostgroups,   @puppetclass, Hostgroup,   :label => _("Host groups") %>
    </div>
    <div class="tab-pane lookup-keys-container" id="smart_class_param">
      <% if @puppetclass.class_params.empty? %>
        <div class="alert alert-success alert-dismissable">
          <%= alert_close %>
          <p><strong>
            <%= _('This Puppet class has no parameters in its signature.') %>
          </strong><br><%= _('To update the class signature, go to the Puppet Classes page and select "Import".') %></p>
        </div>
      <% else %>
        <div class="row">
          <div class='col-md-3'>
            <input placeholder="<%= _('Filter by name') %>" onkeyup="filterByClassParam(this);" type='text' class="form-control">
          </div>
          <div class="form-group col-md-3">
            <div class='input-group'>
              <span class="input-group-addon">@</span>
              <%= select_tag "environment_filter", options_from_collection_for_select(@puppetclass.environments, "id", "name"),
                             :prompt => _("All environments - (not filtered)"),:class=>'form-control', :onchange=>'filterByEnvironment(this)'%>
            </div>
          </div>
          <div class='col-md-6 text-right'>
            <%= documentation_button('4.2.5ParameterizedClasses') %>
          </div>
        </div>
        <div class="smart-var-left col-md-3">
          <ul class="nav nav-pills nav-stacked smart-var-tabs" data-tabs="pills">
            <% @puppetclass.class_params.includes(:environments, :environment_classes, :lookup_values).each do |key| %>
              <li data-used-environments=<%= key.environments.map(&:to_s).to_json %> >
                <a data-toggle="tab" id="pill_<%= key.to_param %>" href="#<%= key.to_param %>" title="<%= key.key.size > 43 ? key : "" %>">
                  <div class="clip"><%= icon_text((key.override ? "flag": ""), key.to_s.tr('_',' '), :kind => 'fa', :title => _('Overridden')) %></div>
                </a>
              </li>
            <% end %>
          </ul>
        </div>
        <div class="tab-content col-md-9 stacked-content">
          <%= f.fields_for :class_params do |lookup_keys_form| %>
            <%= render 'lookup_keys/fields', :f => lookup_keys_form  %>
          <% end %>
        </div>
      <% end %>
    </div>
  </div>

  <%= submit_or_cancel(f, false, { :cancel_path => resource_prev_url_with_search_filters }) %>
<% end %>
